home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / eked-m1.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  6KB  |  270 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; eked-m1.c : start-up and menu code
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <stdio.h>
  22. #include <gemfast.h>
  23. #include <aesbind.h>
  24. #include <vdibind.h>
  25. #include "gm/gem_man.h"
  26. #include "eked-m1.h"
  27. #include "defs.h"
  28. #include "types.h"
  29. #include "externs.h"
  30.  
  31. #define RSC_FILE    "eked-m1.rsc"
  32. #define RSC_ERR        1
  33.  
  34. OBJECT *name_form;
  35. int shared_handle;
  36.  
  37. static OBJECT *menu;
  38. static OBJECT *information;
  39.  
  40. static void gem_init();
  41. static void gem_exit();
  42. static int do_menu(int title, int item);
  43. static int mono_hack(OBJECT *obj);
  44. static void value_opt();
  45.  
  46. int main()
  47. {
  48.   gem_init();
  49.   ic_window();
  50.   ic_newbank();
  51.   do{
  52.     wm_monitor(menu, &do_menu);
  53.   }while(fm_alert(2, QUIT_ALERT) != 1);
  54.   gem_exit();
  55.   return 0;
  56. }
  57.  
  58. static void gem_init()
  59. {
  60.   gm_init();
  61.   if(!rm_load(RSC_FILE)){
  62.     form_alert(1, "[1][Can't find resouce file!][ QUIT ]");
  63.     gm_exit();
  64.     exit(RSC_ERR);
  65.   }
  66.   if(nr_planes == 1)
  67.     rm_map_all(&mono_hack);
  68.   shared_handle = gm_opnvwk();
  69.   rm_gaddr(R_TREE, NAME_FORM, &name_form);
  70.   wm_init();
  71.   ic_init();
  72.   pe_init();
  73.   rm_gaddr(R_TREE, MENU, &menu);
  74.   rm_gaddr(R_TREE, INFORMATION, &information);
  75.   menu_bar(menu, TRUE);
  76.   km_scan_menu(menu);
  77.   graf_mouse(ARROW, 0L);
  78. }
  79.  
  80. static void gem_exit()
  81. {
  82.   menu_bar(menu, FALSE);
  83.   pe_exit();
  84.   ic_exit();
  85.   wm_exit();
  86.   rm_free();
  87.   gm_clsvwk(shared_handle);
  88.   gm_exit();
  89. }
  90.  
  91. static int do_menu(int title, int item)
  92. {
  93.   switch(item){
  94.   case M_INFO:
  95.     (void) fm_dialog(information, 0, (OBJECT *) NULL, 0);
  96.     break;
  97.   case M_QUIT:
  98.     return R_QUIT;
  99.   case M_VIRT_KBD:
  100.     vk_window();
  101.     break;
  102.   case M_MSND_LIST:
  103.     ms_window();
  104.     break;
  105.   case M_DRUM_LIST:
  106.     ds_window();
  107.     break;
  108.   case M_OPEN:
  109.   case M_SAVE_AS:
  110.   case M_SAVE:
  111.   case M_PRINT:
  112.   case M_COPY:
  113.   case M_FLIP:
  114.   case M_ERASE:
  115.   case M_TRANSMIT:
  116.   case M_RECEIVE:
  117.   case M_COMB_LIST:
  118.   case M_PROG_LIST:
  119.   case M_GLOB_EDIT:
  120.     ic_bankop(item);
  121.     break;
  122.   case M_NEW:
  123.     ic_newbank();
  124.     break;
  125.   case M_MIDI:
  126.     midi_opt();
  127.     break;
  128.   case M_VALUES:
  129.     value_opt();
  130.     break;
  131.   case M_DIALOGS:
  132.     ic_dialogs();
  133.     break;
  134.   case M_CYCLE:
  135.     wm_cycle();
  136.     break;
  137.   }
  138.   return 0;
  139. }
  140.  
  141. void mn_bank_sel()
  142. {
  143.   menu[M_OPEN].ob_state &= ~DISABLED;
  144.   menu[M_SAVE_AS].ob_state &= ~DISABLED;
  145.   menu[M_SAVE].ob_state &= ~DISABLED;
  146.   menu[M_PRINT].ob_state &= ~DISABLED;
  147.   menu[M_COPY].ob_state &= ~DISABLED;
  148.   menu[M_FLIP].ob_state &= ~DISABLED;
  149.   menu[M_ERASE].ob_state &= ~DISABLED;
  150.   menu[M_TRANSMIT].ob_state &= ~DISABLED;
  151.   menu[M_RECEIVE].ob_state &= ~DISABLED;
  152.   menu[M_COMB_LIST].ob_state &= ~DISABLED;
  153.   menu[M_PROG_LIST].ob_state &= ~DISABLED;
  154.   menu[M_GLOB_EDIT].ob_state &= ~DISABLED;
  155. }
  156.  
  157. void mn_bank_desel()
  158. {
  159.   menu[M_OPEN].ob_state |= DISABLED;
  160.   menu[M_SAVE_AS].ob_state |= DISABLED;
  161.   menu[M_SAVE].ob_state |= DISABLED;
  162.   menu[M_PRINT].ob_state |= DISABLED;
  163.   menu[M_COPY].ob_state |= DISABLED;
  164.   menu[M_FLIP].ob_state |= DISABLED;
  165.   menu[M_ERASE].ob_state |= DISABLED;
  166.   menu[M_TRANSMIT].ob_state |= DISABLED;
  167.   menu[M_RECEIVE].ob_state |= DISABLED;
  168.   menu[M_COMB_LIST].ob_state |= DISABLED;
  169.   menu[M_PROG_LIST].ob_state |= DISABLED;
  170.   menu[M_GLOB_EDIT].ob_state |= DISABLED;
  171. }
  172.  
  173. static int mono_hack(OBJECT *obj)
  174. {
  175.   if(obj->ob_type == G_BOX && (obj->ob_spec & 0x70) == 0x40)
  176.     obj->ob_spec ^= 0x60;    /* change pattern 4 to pattern 2 */
  177.   return 0;    /* only examine root of each object tree */
  178. }
  179.  
  180. static void value_opt()
  181. {
  182.   static int point_size = 8;
  183.   OBJECT *value_options;
  184.   int roll_mode, size, t;
  185.  
  186.   roll_mode = gm_roll_mode(-1);
  187.   rm_gaddr(R_TREE, VALUE_OPTIONS, &value_options);
  188.   GM_SELECT(roll_mode == R_ROLL, value_options, V_ROLL);
  189.   GM_SELECT(roll_mode == R_RIGHTUP, value_options, V_RIGHTUP);
  190.   GM_SELECT(roll_mode == R_LEFTUP, value_options, V_LEFTUP);
  191.   size = point_size;
  192.   unum_update(value_options + V_SIZE, size);
  193.  
  194.   fm_begin_dialog(value_options, 0);
  195.   do{
  196.     t = fm_run_dialog();
  197.     switch(t){
  198.     case V_SIZE:
  199.       size = fm_roll(value_options, t, size, 8, 20, &unum_update);
  200.       break;
  201.     }
  202.   }while(t != V_OK && t != V_CANCEL);
  203.   fm_end_dialog();
  204.   if(t == V_CANCEL)
  205.     return;
  206.  
  207.   if(value_options[V_ROLL].ob_state & SELECTED)
  208.     roll_mode = R_ROLL;
  209.   else if(value_options[V_RIGHTUP].ob_state & SELECTED)
  210.     roll_mode = R_RIGHTUP;
  211.   else
  212.     roll_mode = R_LEFTUP;
  213.   gm_roll_mode(roll_mode);
  214.   if(size != point_size){
  215.     ls_size(size);
  216.     ms_size(size);
  217.     point_size = size;
  218.   }
  219. }
  220.  
  221. /*
  222.  *    Copy string, padding it out to n characters with spaces
  223.  *    or trucating it to n characters as neccessary.
  224.  *    Terminate with zero as (n+1)th character.
  225.  */
  226. char *strfcpy(char *d, char *s, size_t n)
  227. {
  228.   for(; n > 0 && *s; n--)
  229.     *d++ = *s++;
  230.   for(; n > 0; n--)
  231.     *d++ = ' ';
  232.   *d = '\0';
  233.   return d;
  234. }
  235.  
  236. /*
  237.  *    Copy n characters, converting zeros to spaces.
  238.  *    Terminate with zero as (n+1)th character.
  239.  */
  240. char *korg2str(char *d, char *s, size_t n)
  241. {
  242.   for(; n > 0; s++, n--)
  243.     *d++ = *s ? *s : ' ';
  244.   *d = '\0';
  245.   return d;
  246. }
  247.  
  248. /*
  249.  *    Copy string, padding it out to n characters with spaces
  250.  *    or trucating it to n characters as neccessary.
  251.  *    No terminating zero.
  252.  */
  253. char *str2korg(char *d, char *s, size_t n)
  254. {
  255.   for(; n > 0 && *s; n--)
  256.     *d++ = *s++;
  257.   for(; n > 0; n--)
  258.     *d++ = ' ';
  259.   return d;
  260. }
  261.  
  262. int iszero(char *s, size_t n)
  263. {
  264.   for(; n > 0; n--){
  265.     if(*s++)
  266.       return FALSE;
  267.   }
  268.   return TRUE;
  269. }
  270.